#include "ThreadPoolWork.h"
#include <thread>
#include "log4z.h"

using namespace std;
OSIP_STATIC_IMP(ThreadPoolWork)

ThreadPoolWork::ThreadPoolWork()
{
}

ThreadPoolWork::~ThreadPoolWork()
{
	uninitialization();
}

void ThreadPoolWork::initialization()
{
	int threadNum = std::thread::hardware_concurrency();
	if (threadNum > 0) {
		m_threadPool = new zl::ThreadPool(threadNum * 2);
	}
	else {
		m_threadPool = new zl::ThreadPool();
	}

	LOGFMTI("threadNum:%d  m_threadPool->size():%d", threadNum, m_threadPool->size());
}

void ThreadPoolWork::uninitialization()
{
	m_threadPool->stop();
	delete m_threadPool;m_threadPool = nullptr;
}

size_t ThreadPoolWork::addTask(zl::Task* task)
{
	return m_threadPool->addTask(task);
}

int ThreadPoolWork::size()
{
	return m_threadPool->size();
}